package a_;

import org.junit.Test;

import java.io.*;

public class CharStreamDemo1 {
    @Test
    public void test1() throws IOException {
        OutputStreamWriter osw1 = new OutputStreamWriter(new FileOutputStream("charStream.txt",true),"UTF-8");
        osw1.write('中');
        //刷新缓冲区
        osw1.close();
    }

    @Test
    public void test2() throws IOException {
       //默认字符集
        InputStreamReader isr = new InputStreamReader(new FileInputStream("charStream.txt"));
       //指定字符集
        InputStreamReader isr1 = new InputStreamReader(new FileInputStream("charStream.txt"),"GBK");
       int i;
       while ((i = isr.read()) != -1){
           System.out.println(i);
       }
        System.out.println("------------------------------------------------");
       int j;
       while ((j = isr1.read()) != -1){
           System.out.println(j);
       }
    }
}
